#include <iostream>
#include <set>

struct node
{
    int value;
    node *left = NULL;
    node *right = NULL;
    node(int val) : value(val) {}
};

struct NodePtrComp
{
    bool operator()(const node *lhs, const node *rhs) const
    {
        return lhs->value < rhs->value;
    }
};

void dfs(node *x)
{
    if (x->left && x->right)
    {
        if (x->left->value > x->right->value)
            std::swap(x->left, x->right);
    }
    if (x->left)
    {
        dfs(x->left);
    }
    std::cout << x->value << " ";
    if (x->right)
        dfs(x->right);
}

int main()
{
    int n;
    std::cin >> n;

    std::multiset<node *, NodePtrComp> st;
    while (n--)
    {
        int x;
        std::cin >> x;
        st.insert(new node(x));
    }

    while (st.size() > 1)
    {
        node *a = *st.begin();
        st.erase(st.begin());
        node *b = *st.begin();
        st.erase(st.begin());

        node *c = new node(a->value + b->value);
        c->left = a;
        c->right = b;
        st.insert(c);
    }

    dfs(*st.begin());

    return 0;
}